home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / Powervisor v1.10b disk2.adf / Expressions < prev    next >
Text File  |  1991-09-28  |  25KB  |  787 lines

  1. *------------------------*
  2. * Tutorial : expressions * Sat Sep 28 17:22:55 1991
  3. *------------------------*
  4.  
  5.  
  6. ===================== Commands used in this tutorial =========================
  7.  
  8.    disp        Display integer
  9.    exec        Go to the ExecBase list
  10.    help        Ask for help
  11.    list        Show a list (tasks, libraries, message ports, ...)
  12.    loadfd      Load a fd file
  13.    memory      List memory
  14.    print       Print a string
  15.    remvar      Remove a variable
  16.    scan        Ask input
  17.    task        Go to the task list
  18.    void        Evaluate the arguments given
  19.  
  20.  
  21. ===================== Functions used in this tutorial ========================
  22.  
  23.    alloc       Allocate memory
  24.    cols        Ask the number of columns in logical window
  25.    eval        Evaluate string
  26.    free        Free memory
  27.    if          Conditional evaluation
  28.    lines       Ask the number of rows in logical window
  29.  
  30.  
  31. ============================== Introduction ==================================
  32.  
  33. PowerVisor has a very powerful expression evaluator. Before you continue
  34. reading this file make sure you have mastered the basic features of
  35. PowerVisor (read the file 'GettingStarted' first).
  36.  
  37. First start PowerVisor (if it is not already in memory).
  38.  
  39. PowerVisor has two basic types: ¹strings and ¹integers. Sometimes these two
  40. types collide a bit. In this tutor file I will make you more comfortable
  41. with all the features PowerVisor has in this regard.
  42.  
  43. All commands and functions in PowerVisor expect integers and/or strings
  44. as their arguments. You can use expressions everywhere.
  45.  
  46.  
  47. ============================= Simple integers ================================
  48.  
  49. First we have ²decimal integers :
  50.  
  51. < disp 5 <enter>
  52. > 00000005 , 5
  53.  
  54. < disp 1236 <enter>
  55. > 000004D4 , 1236
  56.  
  57. < disp -100 <enter>
  58. > FFFFFF9C , -100
  59.  
  60. But not (can you see why ?) :
  61.  
  62. < disp 01236 <enter>
  63. > 00001236 , 4662
  64.  
  65. This last notation is used for ²²hexadecimal numbers :
  66.  
  67. < disp 01A <enter>
  68. > 0000001A , 26
  69.  
  70. < disp $1a <enter>
  71. > 0000001A , 26
  72.  
  73. You can see that PowerVisor has two ways to notate a hexadecimal number.
  74. PowerVisor interpretes '0<number>' as a hexadecimal number because this is
  75. very convenient if you 'snap' a hex number from the PowerVisor screen. Such
  76. a number almost always contains some leading zeroes.
  77.  
  78. Note that in the current version of PowerVisor the following command :
  79.  
  80. < disp 1A <enter>
  81.  
  82. does not give an error :
  83.  
  84. > 00000001 , 1
  85.  
  86. This is in fact a bug and it will be solved in a later version of PowerVisor.
  87.  
  88.  
  89. =============================== Expressions ==================================
  90.  
  91. You can use more complex ¹expressions :
  92.  
  93. < disp 5+5 <enter>
  94. > 0000000A , 10
  95.  
  96. < disp 1+(5*9)-(3&5) <enter>
  97. > 0000002D , 45
  98.  
  99. Note that you cannot use spaces in expressions.
  100.  
  101. You can use the following binary operators. The list is from high to
  102. low priority :
  103.  
  104.   * / %       ¹¹multiply, ²²integer divide, ¹¹remainder
  105.   + -         ¹¹add, ¹¹subtract
  106.   << >>       ²²left shift, ²²right shift
  107.   > < >= <=   ²²integer comparisons
  108.   != ==       ³³not equal to, ²²equal to
  109.   &           ²²bitwise and
  110.   ^           ²²bitwise xor
  111.   |           ²²bitwise or
  112.   &&          ²²logical and
  113.   ||          ²²logical or
  114.  
  115. There are also some ²²unary operators :
  116.   -           ¹¹negation
  117.   !           ²²logical not
  118.   ~           ²²bitwise not
  119.   *           ²²contents operator
  120.   &           ²²address operator (explained later)
  121.  
  122. You can also use brackets.
  123. Some examples :
  124.  
  125. < disp 5+(9-(7*(5/(3+~1)))) <enter>
  126. > FFFFFFEB , -21
  127.  
  128. Note that you MUST close all brackets.
  129.  
  130. The contents operator needs some more examples :
  131.  
  132. < disp *4 <enter>
  133. > 07E007E4 , 132122596
  134.  
  135. (This is the pointer to execbase)
  136.  
  137. < disp *4.b <enter>
  138. > 00000007 , 7
  139.  
  140. < disp *4.w <enter>
  141. > 000007E0 , 2016
  142.  
  143. < disp *(2+2).l <enter>
  144. > 07E007E4 , 132122596
  145.  
  146. The syntax of the * operator is:
  147.    '*'<expression>['.' ('b' | 'w' | 'l') ]
  148. 'b', 'w' and 'l' are the size indicators (b = byte, w = word, l = long).
  149. If you do not specify '.', PowerVisor assumes long mode. This operator checks
  150. for illegal addresses :
  151.  
  152. < disp *5 <enter>
  153. > Odd address error !
  154.  
  155. On the ¹68000 processor you cannot read a long at an ²odd address.
  156. PowerVisor will always give this error even if you have a ¹68020/68030
  157. processor.
  158.  
  159.  
  160. ============================= String pointers ================================
  161.  
  162. A ²²string pointer is NOT a string, it is an integer. When you use a string
  163. pointer, PowerVisor will allocate a temporary space for this string and
  164. give you the address.
  165.  
  166. String pointers (and strings for that matter) support the following
  167. operators :
  168.    \           the quote operator
  169.                      \<hex digit><hex digit>
  170.                         is replaced by the ascii character
  171.                      \(<expression>)
  172.                         is replaced by the string representation
  173.                         of the <expression>
  174.                      \(<expression>,<formatstring>)
  175.                         is replaced by <expression> formatted like
  176.                         <formatstring>. <formatstring> is a C-style
  177.                         (printf) formatting string. Use %ld for
  178.                         integers, %lx for hexadecimal integers, %s
  179.                         for strings and %c for characters
  180.    ·           the 'strong quote' operator
  181.                      ·<end char> various characters of all sorts <end char>
  182.                         To type the dot use <alt>+8. Most users will
  183.                         probably never need this operator. It is useful
  184.                         in aliases if you want to take away ALL special
  185.                         interpretations of characters. The ONLY thing
  186.                         that will stop the parsing of the string is the
  187.                         <end char>.
  188.                         The 'salias' alias is an example of an alias
  189.                         using the strong quote (see the 'Aliases' reference
  190.                         file).
  191.  
  192.  
  193. Example :
  194.  
  195. < disp "Hello" <enter>
  196. > 07E50E52 , 132451922
  197.  
  198. < memory 07E50E52 10 <enter>
  199. > 07E50E52: 68656C6C 6F0007E2 1010                           Hello.....
  200.  
  201. PowerVisor remembers the last 10 strings and string pointers (all in one
  202. pool) before it frees them. This means that you can only use 10 string
  203. pointers in one command at the same time.
  204. If you want a permanent string pointer you can use the 'alloc' function.
  205.  
  206.  
  207. The next example illustrates the use of the ²contents operator (*) and
  208. a string pointer :
  209.  
  210. < disp *("Hello"+1).b <enter>
  211. > 00000065 , 101
  212.  
  213. (101 is the ascii value for 'e').
  214.  
  215. Look at the following example :
  216.  
  217. < memory "Left\41\42\43Right" 16 <enter>
  218. > 07EC98A2: 4C656674 41424352 69676874 000007EC              LeftABCRight....
  219.  
  220. The '\' notation is useful for ²unprintable characters (and untypable).
  221. After the '\' follow two hexadecimal digits. If the first character following
  222. the '\' is not a hexadecimal digit the first '\' is ignored :
  223.  
  224. < memory "Left\\Right" 10 <enter>
  225. > 07E5C0BA: 4C656674 5C526967 6874                           Left\Right
  226.  
  227. < memory "Left\"Right" 10 <enter>
  228. > 07E5C0BA: 4C656674 22526967 6874                           Left"Right
  229.  
  230.  
  231. There is one extra feature that you have with quoting. Consider the
  232. following example :
  233.  
  234. < memory "Left\(4+5)Right" 16 <enter>
  235. > 07E31A72: 4C656674 39526967 68740000 00000000              Left9Right......
  236.  
  237. The expression between the two brackets can be as complex as you wish.
  238. You can use variables, functions, ...
  239. You can use an optional ²format string directly after the expression (include
  240. some white space of course). Use standard ¹C-formatting conventions :
  241.  
  242. < memory "Left(4+5,%02ld)Right" 16 <enter>
  243. > 07E31A72: 4C656674 30395269 67687400 00000000              Left09Right.....
  244.  
  245. < memory "Left(65,%lc)Right" 16 <enter>
  246. > 07E31A72: 4C656674 41526967 68740000 00000000              LeftARight......
  247.  
  248.  
  249. ================================== Names =====================================
  250.  
  251. ¹¹Names are probably the most difficult things in the PowerVisor parsing
  252. language. They can be almost everything. I think examples are the best
  253. way to illustrate their purpose :
  254.  
  255. < task <enter>
  256. < list <enter>
  257.  
  258. > Task node name      : Node     Pri StackPtr  StackS Stat Command        Acc
  259. > ---------------------------------------------------------------------------
  260. > RAM                 : 07E25260 00  07E2554E    1200 Rdy             PROC -
  261. > Background Process  : 07E26BA8 00  07E2CBD8    4000 Wait iprefs     (02) -
  262. > RexxMaster          : 07E39BA8 04  07E3A3EA    2048 Wait            (00) -
  263. > SYS:System/CLI      : 07E529C0 00  07E538CA    4096 Wait            (00) -
  264. > ramlib              : 07E1F680 00  07E1FE80    2048 Wait            PROC -
  265. > CON                 : 07E56A20 05  07E57522    3200 Wait            PROC -
  266. > Background CLI      : 07E65518 00  07E65F66    3200 Wait            (01) -
  267. > console.device      : 07E0E1A2 00  07E0F1A4    4096 Wait            TASK -
  268. > PowerSnap 1.0 by Nic: 07E48450 05  07E48C9A    2000 Wait            PROC -
  269. > WB_2.x              : 07E11488 0A  07E11E4E    2400 Wait            PROC -
  270. > DF0                 : 07E17208 0A  07E17BCE    2400 Wait            PROC -
  271. > Workbench           : 07E54930 01  07E56956    8192 Wait            (05) -
  272. > PowerVisor1.0.task  : 07E7CBE0 00  07E7D096    1024 Wait            TASK -
  273. > SCSI bus handler    : 07E0AFD0 0C  07E0B3B6    1000 Wait            TASK -
  274. > scsi.device         : 07E0A3F8 0B  07E0A396    1000 Wait            TASK -
  275. > trackdisk.device    : 07E0F988 05  07E0FB96     512 Wait            TASK -
  276. > Work                : 07E19940 0A  07E1A306    2400 Wait            PROC -
  277. > Background Process  : 07E3B4A0 00  07E52354    4000 Wait clock      (03) -
  278. > input.device        : 07E08AF2 14  07E09AF8    4096 Wait            TASK -
  279. > Background Process  : 07E7B418 04  07E8E386    4000 Run  pv         (04) -
  280.  
  281. < disp powervisor <enter>
  282. > 07E7CBE0 , 132631520
  283.  
  284. In this case we used a name ('powervisor') as an ¹abbreviation for an element
  285. in the ²current list. We could also have written :
  286.  
  287. < disp POWERvi <enter>
  288.  
  289. or
  290.  
  291. < disp 'Powervisor1' <enter>
  292.  
  293. or
  294.  
  295. < disp power <enter>
  296.  
  297. The last command is correct but it is ambiguous in this case since there are
  298. two names in the current list beginning with 'power'. When this is the case
  299. the first match is used (PowerSnap 1.0 in this case).
  300.  
  301. Important to remember is that when we use names for this purpose the
  302. following rules apply :
  303.  
  304.   - you may use quotes (if you want to include spaces for example)
  305.   - the searching is case insensitive
  306.   - you can use abbreviations, i.e. you need not give the full name
  307.  
  308. Consider the following example :
  309.  
  310. < powervisor=5 <enter>
  311.  
  312. < disp powervisor <enter>
  313. > 00000005 , 5
  314.  
  315. < disp 'powervisor' <enter>
  316. > 07E7CBE0 , 132631520
  317.  
  318. < disp powerviso <enter>
  319. > 07E7CBE0 , 132631520
  320.  
  321. < disp powervisor1 <enter>
  322. > 07E7CBE0 , 132631520
  323.  
  324. We have created a ¹¹variable 'powervisor' with value 5. The name 'powervisor'
  325. has now lost it's meaning as an abbreviation for an element in the current
  326. list. Note that we can still use 'powerviso' and 'powervisor1' for the
  327. element in the current list.
  328. So we see that the following rules apply for variables :
  329.  
  330.   - you can't use quotes for variable names (if you do it is interpreted
  331.     as an element in the current list)
  332.   - variable names can't be abbreviated
  333.   - variable names are case insensitive
  334.  
  335. When you use quotes you ²force interpretation of the ²current list. There
  336. is a shorter and better way to do this (also see the 'List operator'
  337. section) :
  338.  
  339. < disp :powervisor <enter>
  340. > 07E7CBE0 , 132631520
  341.  
  342. Now we remove the created variable :
  343.  
  344. < remvar powervisor <enter>
  345.  
  346. There is still a third way to interprete names. But it is at this moment
  347. not appropriate to give examples. A name can also be a ¹symbol
  348. for the ³current debug task (see debugging). The rules for symbol names
  349. are :
  350.  
  351.   - you can use quotes
  352.   - symbol names are case sensitive
  353.   - no abbreviations are possible
  354.  
  355. In case of ambiguity observe the following order of checking :
  356.  
  357.   - PowerVisor will first check if it is a variable
  358.   - If it is not a variable it could be a symbol for the current debug task
  359.   - If it is not a symbol PowerVisor will search the current list
  360.  
  361. If you use quotes for the name, PowerVisor will skip the variable testing
  362. and only test if it is a symbol or a list element. If you use the ':'
  363. operator (see above) PowerVisor will only search the current list.
  364.  
  365.  
  366. Warning ! A name is strictly a sequence of characters. If you want to
  367. use special operators like the quote operator you should normally use
  368. strings (with single quotes). In most cases PowerVisor will not complain
  369. when you use a quote operator or something else in a name, but remember
  370. that the result is not always satisfactory. Problems can occur when
  371. you use the name in complex expressions containing functions and groups.
  372. If you use the quote operator in that case, the chances are high that
  373. PowerVisor will get confused. You can get a error message like :
  374.    'Your brackets are really out of order !'
  375. even if your brackets may seem allright to you.
  376.  
  377. The following is an illegal example :
  378.  
  379. < a=alloc(s,' testing ') <enter>
  380.  
  381. < d if(1,{print test\(a,%s)it\0a},2) <enter>
  382. > Your brackets are really out of order !
  383.  
  384. You should type :
  385.  
  386. < d if(1,{print 'test\(a,%s)it\0a'},2) <enter>
  387. > test testing it
  388. > 07EECDA8 , 133090728
  389.  
  390.  
  391. ================================ Functions ===================================
  392.  
  393. ¹¹Functions are a special form of ¹variables. Internally they are almost the
  394. same. Type :
  395.  
  396. < help functions <enter>
  397.  
  398. > General functions
  399. > -----------------
  400. > ALLOC      : allocate memory          LASTMEM    : give last memory
  401. > FREE       : free memory              LASTFOUND  : last search address
  402. > REALLOC    : reallocate memory        PEEK       : peek value in structure
  403. > GETSIZE    : give size of memoryblock APEEK      : peek address
  404. > ISALLOC    : is memory a pv-block ?   STSIZE     : get structure size
  405. > KEY        : returns pressed key      RFCMD      : refresh command
  406. > QUAL       : qualifier for last key   RFRATE     : refresh rate
  407. > GETCOL     : get logical col width    GETLWIN    : current logical window
  408. > GETROW     : get logical row height   GETERROR   : get error of routine
  409. > TOPPC      : get debug win top pc     TAGLIST    : get current tag list
  410. > BOTPC      : get debug win bottom pc  EVAL       : evaluate argument string
  411. > ISBREAK    : check if breakpoint      IF         : conditional evaluation
  412. > GETDEBUG   : get current debug ptr    CURLIST    : current list
  413. > GETX       : get the current x coord  COLS       : get max nr of cols
  414. > GETY       : get y coord              LINES      : get max nr lines
  415. > GETCHAR    : get the current char     BASE       : get first listelem
  416.  
  417. Since functions are so much like variables the same evaluation rules apply
  418. to them (see the previous section: 'names'). You must use the full name
  419. (no abbreviations). The only exception is that you must use brackets after
  420. the function name even if there are no arguments.
  421.  
  422. Some examples :
  423.  
  424. < disp lines(main)
  425. > 00000035 , 53
  426.  
  427. This means that I have 53 lines on my PowerVisor screen.
  428. (See the 'screen' manual for more complete information about this function).
  429. 'main' is the argument for the function.
  430.  
  431. The following is incorrect (There is a space between 'lines' and '(main)') :
  432.  
  433. < disp lines (main)
  434. > You must use brackets with functions !
  435.  
  436.  
  437. ============================ Library functions ===============================
  438.  
  439. PowerVisor has the very powerful capability to execute ²library functions.
  440. You only need to load the corresponding ¹fd-file (in the fd2.0 or fd1.3
  441. subdirectory) :
  442.  
  443. < loadfd exec :fd2.0/exec_lib.fd <enter>
  444.  
  445. or
  446.  
  447. < loadfd libs:exec :fd2.0/exec_lib.fd <enter>
  448.  
  449. > New functions: 0000007E,126
  450.  
  451. PowerVisor will then know how to call all functions from the exec library.
  452.  
  453. You can now use all the exec library functions as if they were normal
  454. PowerVisor functions :
  455.  
  456. < disp typeofmem(100000) <enter>
  457. > 00000303 , 771
  458.  
  459. < disp openlibrary("exec.library",0) <enter>
  460. > 07E007E4 , 132122596
  461.  
  462. The following rules for ²²library functions apply :
  463.  
  464.   - you MUST use brackets even if there are no arguments (like functions)
  465.   - you MUST close the brackets for the library function arguments. This
  466.     means that if you use an expression as an argument you must close the
  467.     brackets for this expression as well
  468.   - you cannot use abbreviations for library functions
  469.   - library function names are case insensitive
  470.   - you cannot use quotes
  471.  
  472.  
  473. ============================ The list operator ===============================
  474.  
  475. Example :
  476.  
  477. < exec <enter>
  478. < list <enter>
  479.  
  480. > SoftVer      : 00CF     | LowMemChkSum : 0000     | ChkBase      : F81FF81B
  481. > ColdCapture  : 00000000 | CoolCapture  : 00000000 | WarmCapture  : 00000000
  482. > SysStkUpper  : 07E02248 | SysStkLower  : 07E00A48 | MaxLocMem    : 00200000
  483. > DebugEntry   : 00F82E28 | DebugData    : 00000000 | AlertData    : 00000000
  484. > MaxExtMem    : 00000000 | ChkSum       : A366     | ThisTask     : 07E7B418
  485. > IdleCount    : 000CC6E6 | DispCount    : 0005444A | Quantum      : 0004
  486. > Elapsed      : 0004     | SysFlags     : 0000     | IDNestCnt    : FF
  487. > TDNestCnt    : F4       | AttnFlags    : 0017     | AttnResched  : 0000
  488. > ResModules   : 07E00428 | TaskTrapCode : 07E80AE6 | TaskExceptCod: 00F83A9C
  489. > TaskExitCode : 00F823D0 | TaskSigAlloc : 0000FFFF | TaskTrapAlloc: 8000
  490. > VBlankFreq   : 32       | PowerSupplyFr: 32       | KickTagPtr   : 00000000
  491. > KickCheckSum : 00000000 | RamLibPrivate: 07E1F470 | EClockFreq   : 000AD303
  492. > CacheCtrl    : 00002919 | TaskID       : 00000001 | PuddleSize   : 00000000
  493. > MMULock      : 00000000 |
  494.  
  495. We are now in the execbase ²structure list.
  496.  
  497. < disp quantum <enter>
  498. > 00000004 , 4
  499.  
  500. The same rules apply as for normal list element searching (see the 'Names'
  501. section).
  502.  
  503. If there are possible ambiguities you can use the ':' operator.
  504.  
  505. < disp :quantum <enter>
  506. > 00000004 , 4
  507.  
  508. If you want to change the quantum variable you can use the '&' operator
  509. (This operator is only supported for lists of this type (exec, graf, intb,
  510. ...)) :
  511.  
  512. < disp &exec:quantum <enter>
  513. > 07E00904 , 132122884
  514.  
  515. This operator returns the address of the quantum variable in the exec base
  516. list.
  517.  
  518. You can now use this address to change the variable (also see the 'Assignment'
  519. section) :
  520.  
  521. < *&exec:quantum.w=16 <enter>
  522.  
  523. You can also use the list name before the operator (useful if you are in
  524. another current list) :
  525.  
  526. < d exec:quantum <enter>
  527. > 00000004 , 4
  528.  
  529.  
  530. =============================== Assignment ===================================
  531.  
  532. We have already used ¹¹assignment a few times. We used it to assign a value
  533. to a ¹variable, and we used it (in the previous section) to assign a value
  534. to a memory location. Here are some more examples :
  535.  
  536. < a=4 <enter>
  537. < b=5 <enter>
  538. < disp a+b <enter>
  539. > 00000009 , 9
  540.  
  541. < var100=100 <enter>
  542. < var100=var100+var100 <enter>
  543. < disp var100+var100 <enter>
  544. > 00000190 , 400
  545.  
  546. In this form we use assignment to assign a value to a variable.
  547.  
  548. Do not put spaces arround the '=' operator. Otherwise PowerVisor will
  549. try to execute the variable as a command and the '=' as an argument.
  550.  
  551. One more example :
  552.  
  553. < mem=alloc(n,100) <enter>
  554. < *mem=$11111111 <enter>
  555. < *(mem+4).w=$2222 <enter>
  556. < *(mem+6).b=$33 <enter>
  557.  
  558. < memory mem 16 <enter>
  559. > 07E7761A: 11111111  22223300  00000000  00000000           ....""3.........
  560.  
  561. < void free(mem) <enter>
  562.  
  563. With the 'alloc' function we allocated 100 bytes of memory. (The 'n' argument
  564. means the next argument is a number (see the 'alloc' function for more
  565. details). Then we fill this memory with some values. With the 'memory'
  566. command we display them.
  567. After that we use the 'free' function to free our ²allocated memory. Note
  568. that PowerVisor will automatically ²free memory allocated with 'alloc' when
  569. PowerVisor quits.
  570.  
  571.  
  572. =========================== The group operator ===============================
  573.  
  574. Sometimes it is conveniant to ³group several commands together. You can do
  575. just this with the ²²group operator. You can use the group operator in two
  576. different ways. As a command or as a function. Here are some examples :
  577.  
  578. Using the group operator as a command :
  579.  
  580. < {disp 3;disp 5;disp 7} <enter>
  581. > 00000003 , 3
  582. > 00000005 , 5
  583. > 00000007 , 7
  584.  
  585. < {{disp 1;{{disp 2};disp 3};disp 4};disp 5} <enter>
  586. > 00000001 , 1
  587. > 00000002 , 2
  588. > 00000003 , 3
  589. > 00000004 , 4
  590. > 00000005 , 5
  591.  
  592. < {a=2;b=3;disp a*b} <enter>
  593. > 00000006 , 6
  594.  
  595. You can see that the sole purpose of this operator is to allow you to
  596. give more than one command on the commandline. This can be very useful
  597. when some command expects another command as an argument (see the
  598. 'refresh' command).
  599.  
  600. You can also use the group operator as a function :
  601.  
  602. < disp {a=4}*2 <enter>
  603. > 00000008 , 8
  604.  
  605. This command will first assign 4 to 'a' and then execute 'disp 4*2'.
  606.  
  607. < disp {a=4;temp=a*7;void temp+temp*(temp/4)} <enter>
  608. > 000000E0 , 224
  609.  
  610. The 'void' command simply evaluates all it's arguments. It does not
  611. display anything.
  612.  
  613. < disp {disp 1}+2 <enter>
  614. > 00000001 , 1
  615. > 00000003 , 3
  616.  
  617. When the group operator is used as a function, it is the last executed
  618. command in this group that determines the ²return value. The return value
  619. is different for each command. Look at the command reference for more
  620. details.
  621.  
  622.  
  623. ================================= Strings ====================================
  624.  
  625. All previous sections covered integers. PowerVisor also uses ¹¹strings. A
  626. string is very easy. When a command expects a string, almost everything
  627. is correct. Some examples :
  628.  
  629. < print Hello <enter>
  630. > Hello
  631.  
  632. < print Hello\0a <enter>
  633. > Hello
  634.  
  635. Notice the difference between these two commands. If you do not explicitely
  636. ask for a <enter> at the end of the line you will not get one. '\0a' is the
  637. linefeed character.
  638.  
  639. < print 'Hello\0a' <enter>
  640. > Hello
  641.  
  642. < print 5+6 <enter>
  643. > 5+6
  644.  
  645. < print Complete rubbish <enter>
  646. > Complete
  647.  
  648. < print 'Complete rubbish' <enter>
  649. > Complete rubbish
  650.  
  651. < print 'Complete rubbish <enter>
  652. > Complete rubbish
  653.  
  654. < print "Complete rubbish" <enter>
  655. > Complete rubbish
  656.  
  657. < print 'a\0ab\0ac\0ad\0a' <enter>
  658. > a
  659. > b
  660. > c
  661. > d
  662.  
  663. < print Hello\ you <enter>
  664. > Hello you
  665.  
  666. < print 'Hello you' <enter>
  667. > Hello you
  668.  
  669. Strings are very versatile. Even the notation for ²string pointers (double
  670. quotes) is accepted.
  671.  
  672. You can also use the backquote operator :
  673.  
  674. < a="Hello there\0a" <enter>
  675. < print a <enter>
  676. > a
  677.  
  678. < print \(a,%s)\0a <enter>
  679. > Hello there
  680.  
  681. Strings (like string pointers) also support the special integer quoting
  682. feature :
  683.  
  684. < a=1 <enter>
  685. < print 'Testing \(a) \(2,%03ld) \(11+11+11,%04lx) \(65,%lc) !\0a' <enter>
  686. > Testing 1 002 0021 A !
  687.  
  688. < print 'First string : \("Second string",%6.6s).\0a' <enter>
  689. > First string : Second.
  690.  
  691.  
  692. ========================== Some useful functions =============================
  693.  
  694. You can make ²²conditional expressions using the 'if' function. Here is an
  695. example :
  696.  
  697. < a=2 <enter>
  698. < disp if(a==2,1000+5,2000) <enter>
  699. > 000003ED , 1005
  700.  
  701. A very complex example :
  702.  
  703. < disp if(a==3,{disp 3*3;void 1},if(a==2,{disp 2*2;void 1},0))
  704. > 00000004 , 4
  705. > 00000001 , 1
  706.  
  707. This completely useless command computes the square of the variable 'a',
  708. but only if 'a' is equal to 2 or to 3. It also prints the value 1 if 'a'
  709. is equal to 2 or to 3, and 0 if it isn't.
  710.  
  711. I think some detailed explanation can be useful here :-)
  712.  
  713.    The 'disp' command takes it's first argument and prints it.
  714.    This argument is equal to :
  715.  
  716.       if(a==3,{disp 3*3;void 1},if(a==2,{disp 2*2;void 1},0))
  717.  
  718.    The first thing that is evaluated is the 'if' function. The 'if' function
  719.    has three arguments :
  720.  
  721.       one number :
  722.          a==3
  723.  
  724.       and two other expressions :
  725.          {disp 3*3;void 1}
  726.          if(a==2,{disp 2*2;void 1},0)
  727.  
  728.    If 'a' is equal to 3 the first string is taken and evaluated.
  729.  
  730.       This results in evaluation of the following expression :
  731.  
  732.          {disp 3*3;void 1}
  733.  
  734.       This is a ²group expression (see the ²group operator). The group operator
  735.       executes all the commands in it and returns as a result the result
  736.       from the last executed command. This results in the execution of :
  737.  
  738.          disp 3*3
  739.  
  740.       and
  741.  
  742.          void 1
  743.  
  744.       So 9 is printed on the screen and 1 is returned as a result from
  745.       the group operator (the 'void' command simply evaluates all it's
  746.       arguments).
  747.  
  748.       So the result of the first 'if' function is 1 (but 9 is already
  749.       printed). This result is printed. So you have 9 and 1 as output.
  750.  
  751.       ! End evaluation !
  752.  
  753.    If 'a' is not equal to 3 the second string is taken and evaluated.
  754.  
  755.       This results in evaluation of the following string :
  756.  
  757.          if(a==2,{disp 2*2;void 1},0)
  758.  
  759.       This is again an 'if' expression and is evaluated analogous.
  760.  
  761. If you happen to have an ¹expression in a string (this could be a string typed
  762. in by the user) you can evaluate it using the 'eval' function :
  763.  
  764. Ask for input ('scan' returns a pointer to a string. We can also find this
  765. pointer in the predefined constant 'input') :
  766.  
  767. < scan <enter>
  768.  
  769. Type an expression :
  770.  
  771. ????< 10+5 <enter>
  772.  
  773. See if the string is really correct :
  774.  
  775. < print \(input,%s)\0a <enter>
  776. > 10+5
  777.  
  778. Evaluate it :
  779.  
  780. < disp eval(input) <enter>
  781. > 0000000F , 15
  782.  
  783. or you can of course type :
  784.  
  785. < disp eval("10+5") <enter>
  786. > 0000000F , 15
  787.